<?php if(!defined("HDPHP_PATH"))exit;C("SHOW_NOTICE",FALSE);?><table class="table1">
<?php if($attr <> ''){?>
<tr>
		<th class="w100">属性</th>
		<td>
		<table id='goodsAttr'>
			<?php $hd["list"]["a"]["total"]=0;if(isset($attr) && !empty($attr)):$_id_a=0;$_index_a=0;$lasta=min(1000,count($attr));
$hd["list"]["a"]["first"]=true;
$hd["list"]["a"]["last"]=false;
$_total_a=ceil($lasta/1);$hd["list"]["a"]["total"]=$_total_a;
$_data_a = array_slice($attr,0,$lasta);
if(count($_data_a)==0):echo "";
else:
foreach($_data_a as $key=>$a):
if(($_id_a)%1==0):$_id_a++;else:$_id_a++;continue;endif;
$hd["list"]["a"]["index"]=++$_index_a;
if($_index_a>=$_total_a):$hd["list"]["a"]["last"]=true;endif;?>

				<tr>
					<th>
						<?php echo $a['attr_name'];?>
					</th>
				<td><?php echo $a['html'];?></td>	
				</tr>
			<?php $hd["list"]["a"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>							
		</table>
		</td>
</tr>
<?php }?>
</table>
<table class="table1">
<tr>
		<th class="w100">库存</th>
		<td>
		<table id='goodsStock'>
			<tr>
				<?php $hd["list"]["s"]["total"]=0;if(isset($spec[0]) && !empty($spec[0])):$_id_s=0;$_index_s=0;$lasts=min(1000,count($spec[0]));
$hd["list"]["s"]["first"]=true;
$hd["list"]["s"]["last"]=false;
$_total_s=ceil($lasts/1);$hd["list"]["s"]["total"]=$_total_s;
$_data_s = array_slice($spec[0],0,$lasts);
if(count($_data_s)==0):echo "";
else:
foreach($_data_s as $key=>$s):
if(($_id_s)%1==0):$_id_s++;else:$_id_s++;continue;endif;
$hd["list"]["s"]["index"]=++$_index_s;
if($_index_s>=$_total_s):$hd["list"]["s"]["last"]=true;endif;?>

					<td><?php echo $s['attr_name'];?></td>
				<?php $hd["list"]["s"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>
				<!--<td>
					价格
				</td>
				<td>
					库存
				</td>
				<td colspan='2'>
					货号
				</td>-->
			</tr>
			<?php if(is_array($spec)){?><?php  foreach($spec as $key=>$stock){ ?>
			<tr>
				
					<?php if(is_array($stock)){?><?php  foreach($stock as $key=>$s){ ?>
						<td><?php echo $s['html'];?></td>
					<?php }}?>
				<!--<td>
					<input type="text" name='spec[price][]' class='w100'/>
				</td>
				<td>
					<input type="text" name='spec[stock][]' class='w100'/>
				</td>
				<td>
					<input type="text" name='spec[sn][]' class='w100'/>
				</td>-->
				<td>
					<button type='button' class="hd-cancel addStockForm" >添加</button>
				</td>
			</tr>				
			<?php }}?>			
		</table>
		</td>
</tr>
</table>
<script>
	$(".addStockForm").live('click',function(){
		var tr = $(this).parents('tr').eq(0).clone().find('input').val('').end();
		//将按钮文字改为移除
		tr.find('button').html('移除').attr('class','hd-cancel delStockForm');
		$("#goodsStock").append(tr);
	})
	$(".delStockForm").live('click',function(){
		var tr = $(this).parents('tr').eq(0).remove();
	})
	//当有价格变化时，取库存中最低的价格做为商品主表价格
	$('[name*=price]').live('blur',function(){
		var t= $(this).val()*1;
		//如果价格为0，就还是用旧的数据
		if(!t)return;
		price=t;
		$("[name='spec[price][]']").each(function(i){
			var s =$("[name='spec[price][]']").eq(i).val()*1;
			//价格不为0时才比较
			if(s!=0)price=Math.min(s,price);
		})
		$('[name=price]').val(price);
	})
	$('[name*=price]').live('blur',function(){
		if(!parseInt($(this).val())){
			$(this).val('');
		}
	});
	$('[name*=stock]').live('blur',function(){
		if(!parseInt($(this).val())){
			$(this).val('');
		}
	});
</script>

















